﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace FileLog
{
    public static class FileLoggerExt
    {
        public static ILoggingBuilder AddFile(this ILoggingBuilder loggingBuilder, Action<FileLogOptins>? optionsConfigure = null)
        {
            var options = new FileLogOptins();
            loggingBuilder.ClearProviders();
            var opt = new FileLogOptins();
            optionsConfigure?.Invoke(opt);
            loggingBuilder.Services.AddSingleton(opt);
            loggingBuilder.Services.TryAddEnumerable(
                       ServiceDescriptor.Singleton<ILoggerProvider, FileLoggerLoggerProvider>());
            loggingBuilder.Services.AddSingleton<FileLoggingProcessor>();
            return loggingBuilder;
        }
    }
}
